﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HyperlinkTagEditor.App;
using System.Collections;
using System.Collections.Generic;
namespace HyperLinkTagEditor.Test
{
    [TestClass]
    public class UnitTest1
    {
        public List<String> IncludeUrls { get; set; }
        public List<String> ExcludeUrls { get; set; }
        public Hashtable UserParameters { get; set; }
        public String MainParameter { get; set; }
        
        public UnitTest1()
        {

            ExcludeUrls = new List<string>();
            IncludeUrls = new List<string>();
            UserParameters = new Hashtable();
            SetupForTest();
        }


        private void SetupForTest()
        {

            MainParameter = "?cid=abc";

            ExcludeUrls.AddRange(new String[] {
            "http://www.elle.co.jp",
            "http://www.elle.co.jp/decor",
            "http://www.elle.co.jp/atable",
            "http://www.ellegirl.jp",
            "http://www.ellemaman.jp",
            "http://www.25ans.jp",
            "http://www.the-wedding.jp"});


            IncludeUrls.AddRange(new String[] {
            "https://www.elle.co.jp",
            "http://www.elle.co.jp",
            "http://sp.elle.co.jp",
            "http://ellegirl.jp",
            "http://www.ellegirl.jp",
            "http://www.ellemaman.jp",
            "http://www.mensclub.jp",
            "http://sp.mensclub.jp",
            "http://www.25ans.jp",
            "http://sp.25ans.jp",
            "http://www.the-wedding.jp",
            "http://www.hearst.co.jp",
            "https://www.facebook.com",
            "http://www.youtube.com",
            "http://pinterest.com",
            "http://elleshop.jp"});


            UserParameters.Add("contact","contact_email=abc@xyz.com");
            UserParameters.Add("news", "?news_online=1");



        }


        [TestMethod]
        public void AppyRulesHTMLContactEmail()
        {

            String InputUrl = "http://www.hearst.co.jp/contact/top/?utm_source=em130321t&cmpid=em130321t&mid=em130321t&custid=${顧客コード}";
            String ExceptedOutputUrl = "http://www.hearst.co.jp/contact/top/?utm_source=em130321t&cmpid=em130321t&mid=em130321t&custid=${顧客コード}&contact_email=abc@xyz.com";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.HTML, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }


        [TestMethod]
        public void AppyRulesHTMLNews()
        {

            String InputUrl = "http://www.elle.co.jp/culture/news/celeb-cinema-13_0314";
            String ExceptedOutputUrl = "http://www.elle.co.jp/culture/news/celeb-cinema-13_0314?news_online=1";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.HTML, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }

        [TestMethod]
        public void AppyRulesHTMLInclude()
        {

            String InputUrl = "http://www.elle.co.jp/acv";
            String ExceptedOutputUrl = "http://www.elle.co.jp/acv?cid=abc";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.HTML, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }


        [TestMethod]
        public void AppyRulesHTMLNoMatchForInclude()
        {

            String InputUrl = "http://yahoo.com";
            String ExceptedOutputUrl = "http://yahoo.com";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.HTML, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }

        [TestMethod]
        public void AppyRulesHTMLCancel()
        {

            String InputUrl = "http://www.elle.co.jp/cancel";
            String ExceptedOutputUrl = "http://www.elle.co.jp/cancel";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.HTML, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }

        /*==================== TEXT FILE ================ */
        [TestMethod]
        public void AppyRulesTEXTContactEmail()
        {

            String InputUrl = "http://www.hearst.co.jp/contact/top/?utm_source=em130321t&cmpid=em130321t&mid=em130321t&custid=${顧客コード}";
            String ExceptedOutputUrl = "http://www.hearst.co.jp/contact/top/?utm_source=em130321t&cmpid=em130321t&mid=em130321t&custid=${顧客コード}&contact_email=abc@xyz.com";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.TEXT, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }


        [TestMethod]
        public void AppyRulesTEXTNews()
        {

            String InputUrl = "http://www.elle.co.jp/culture/news/celeb-cinema-13_0314";
            String ExceptedOutputUrl = "http://www.elle.co.jp/culture/news/celeb-cinema-13_0314?news_online=1";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.TEXT, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }

        [TestMethod]
        public void AppyRulesTEXTInclude()
        {

            String InputUrl = "http://www.elle.co.jp/acv";
            String ExceptedOutputUrl = "http://www.elle.co.jp/acv?cid=abc";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.TEXT, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }


        [TestMethod]
        public void AppyRulesTEXTNoMatchForInclude()
        {

            String InputUrl = "http://yahoo.com";
            String ExceptedOutputUrl = "http://yahoo.com";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.TEXT, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, false);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }

        [TestMethod]
        public void AppyRulesTEXTCancel()
        {

            String InputUrl = "http://www.elle.co.jp/cancel";
            String ExceptedOutputUrl = "http://www.elle.co.jp/cancel";

            String OutputUrl = URLUtilities.ApplyRulesToURL(InputUrl, FileType.TEXT, IncludeUrls, ExcludeUrls, UserParameters, MainParameter, true);

            Assert.AreEqual(ExceptedOutputUrl, OutputUrl);

        }

        
    }
}
